﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 编码流水
    /// </summary>
    public partial class CF_CodeSerial : BaseEntity
    {
        /// <summary>
        /// 公司Id
        /// </summary>
        public string CompanyId { get; set; }
        /// <summary>
        /// 类型Id
        /// </summary>
        public string CodeTypeId { get; set; }
        /// <summary>
        /// 参数名称
        /// </summary>
        public string ParaName { get; set; }
        /// <summary>
        /// 参数值
        /// </summary>
        public string ParaValue { get; set; }
        /// <summary>
        /// 流水号
        /// </summary>
        public int SerialNum { get; set; }
    }

    public partial class CF_CodeSerial : BaseEntity
    {
        /// <summary>
        /// 仓库
        /// </summary>
        //public Bas_Whse Whse { get; set; }
        public CF_CodeType CodeType { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class CF_CodeSerialTypeConfig : BaseEntityTypeConfig<CF_CodeSerial>, IEntityTypeConfiguration<CF_CodeSerial>
    {
        public override void Configure(EntityTypeBuilder<CF_CodeSerial> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            //builder.HasOne(o => o.Whse).WithMany().HasForeignKey(p => p.WhseId).OnDelete(DeleteBehavior.ClientCascade);
            builder.HasOne(m => m.CodeType).WithMany().HasForeignKey(k => k.CodeTypeId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.CodeTypeId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.ParaName).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.ParaValue).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.SerialNum).IsRequired().HasDefaultValue(0);
            #endregion

            #region 备注
            builder.HasComment("编码流水");
            builder.Property(p => p.CodeTypeId).HasComment("类型Id");
            builder.Property(p => p.ParaName).HasComment("参数名称");
            builder.Property(p => p.ParaValue).HasComment("参数值");
            builder.Property(p => p.SerialNum).HasComment("流水号");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
